package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Account;
import com.red.result.Result;
import com.red.service.AccountService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @ApiOperation("根据条件查询用户")
    @ApiImplicitParam(name = "phone",value = "手机号码")
    @GetMapping("/select")
    public Result findAll(String phone){
        return new Result(
                accountService.list(
                        new QueryWrapper<Account>()
                                .like(phone!=null,"phone",phone)
                )
        );
    }

    @ApiOperation("添加用户")
    @PostMapping("/save")
    public Result save(Account account){
        return new Result(accountService.save(account));
    }

    @ApiOperation("修改用户")
    @PutMapping("/update")
    public Result update(Account account){
        return new Result(accountService.updateById(account));
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(accountService.removeById(id));
    }
}
